//
//  ZXDownloadFile.h
//  ZXDownload
//
//  Created by xin on 2018/5/9.
//  Copyright © 2018年 魏鑫. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "NSObject+ExpendFileAttributes.h"

/**
 文件下载状态
 
 - ZXDownloadFileStateNone:         默认状态
 - ZXDownloadFileStateResume:       等待
 - ZXDownloadFileStateDownloading:  下载中
 - ZXDownloadFileStateSuspened:     暂停
 - ZXDownloadFileStateCompleted:    完成
 - ZXDownloadFileStateFailed:       失败
 */
typedef NS_ENUM(NSUInteger, ZXDownloadFileState) {
    ZXDownloadFileStateNone,
    ZXDownloadFileStateResume,
    ZXDownloadFileStateDownloading,
    ZXDownloadFileStateSuspened,
    ZXDownloadFileStateCompleted,
    ZXDownloadFileStateFailed
};


@interface ZXDownloadFile : NSObject

typedef void (^ZXProgressBlock)(NSProgress * _Nonnull, ZXDownloadFile *);
typedef void (^ZXSuccessBlock)(NSURL * _Nonnull);
typedef void (^ZXFailureBlock)(NSError * _Nonnull);

/**
 *  下载文件的URL
 */
@property (nonatomic, copy) NSString * fileURL;

/**
 *  文件本地地址
 */
@property (nonatomic, copy) NSString * filePath;

/**
 *  文件名
 */
@property (nonatomic, copy) NSString * fileName;

/**
 *  文件类型
 */
@property (nonatomic, copy) NSString * fileType;

/**
 *  已写入数据长度
 */
@property (nonatomic, assign) long long totalBytesWritten;

/**
 *  文件数据总长度
 */
@property (nonatomic, assign) long long totalBytesExpectedToWrite;

/**
 *  文件下载状态
 */
@property (nonatomic, assign) ZXDownloadFileState state;

/**
 *  进度
 */
@property (nonatomic, copy) NSProgress *progress;
/*
 *  写文件流
 */
@property (strong, nonatomic) NSOutputStream *stream;

/**
 *  已读文件长度
 */
@property (nonatomic, assign) NSUInteger totalRead;

/**
 *  下载时间
 */
@property (nonatomic, strong) NSDate *date;

/**
 *  下载速度
 */
@property (nonatomic, copy) NSString * speed;

@property (nonatomic, copy) ZXProgressBlock zx_progressBlock;

@property (nonatomic, copy) ZXSuccessBlock zx_successBlock;

@property (nonatomic, copy) ZXFailureBlock zx_failureBlock;

/**
 初始化下载文件对象

 @param url 下载地址
 @return 下载文件对象
 */
- (instancetype)initWithURL:(nullable NSString *)url;

/**
 字节转换，把速度转换成KB或MB

 @param size 字节长度
 @return 字节字符串
 */
- (NSString *)formatByteCount:(long long)size;

/**
 自定义字节转换，把速度转为byte KB MB GB...

 @param size 字节长度
 @return 字节字符串
 */
- (NSString *)customFormatByteCount:(long long)size;

- (NSDictionary *)fileInfo;

@end
